package com.c.ctgproject.ui.collect

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.c.ctgproject.adapter.guang.MaterialOutOrderDetailAdapter
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityMaterialOutDetailBinding
import com.c.ctgproject.entity.guang.MaterialOutDetailEntity
import com.c.ctgproject.entity.guang.MaterialOutOrderEntity
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.getGson
import com.c.ctgproject.utils.noDataHandler
import com.c.ctgproject.wiget.common.CarInfoLayout

/**
 *作者:LiBW
 *创建日期: 2021/9/18
 *描述: 物料详情
 */
class MaterialOutDetailActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityMaterialOutDetailBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root
    private val orderId by lazy { intent.getIntExtra(MyConstants.ORDER_ID, -1) }
    private val mData by lazy { intent.getSerializableExtra(MyConstants.DATA) as MaterialOutOrderEntity.DataBean.ListBean }
    override fun event() {
        //  * outOrderId : 15
        //             * bizNo : WLCK-20210918-0015
        //             * outType : 2
        //             * customer : 4666
        //             * remark :
        //             * createPersonName : 广阿发
        //             * createTime : 2021-09-18 16:21:32
        mData.let {data->
            val outType = when (data.outType) {
                1 -> "销售出库"
                2 -> "借用出库"
                3 -> "其他出库"
                else -> "暂无数据"
            }
            mBinding.mContainer1.addView(CarInfoLayout(this, "出库类型", outType))
            mBinding.mContainer1.addView(CarInfoLayout(this, "流水号", data.bizNo.noDataHandler()))
            mBinding.mContainer1.addView(CarInfoLayout(this, "客户", data.customer.noDataHandler()))
            mBinding.mContainer1.addView(CarInfoLayout(this, "提交人", data.createPersonName.noDataHandler()))
            mBinding.mContainer1.addView(CarInfoLayout(this, "提交时间", data.createTime.noDataHandler()))
            mBinding.mContainer1.addView(CarInfoLayout(this, "备注", data.remark.noDataHandler()))
        }


        ApiMethods.apiSubscribe(ApiMethods.retrofit.materialOutDetail(orderId), MyObserverHandlerLoading(this, loading) {
            MyLog.d("回调:$it")
            val data = getGson().fromJson(it, MaterialOutDetailEntity::class.java).data
            data?.let {list->
                val adapter=MaterialOutOrderDetailAdapter(this,list)
                mBinding.mRecyclerView.adapter=adapter
                mBinding.mRecyclerView.layoutManager=LinearLayoutManager(this)
            }
        })
    }

    override fun click() {

    }

}